/**
 * 模拟两个窗口同时卖票，出现线程安全问题及解决方法
 * synchronized 的使用（锁机制）
 *
 */
public class ThreadDemo1 implements Runnable {
    private int count = 100;

    public  void run(){

            while (count > 0) {
                synchronized (this) {
                    if (count > 0) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("ThreadName=" + Thread.currentThread().getName() + ",\t 出售第:" + count--);

                    }
                }

        }
    }
}
